package com.weasel.weixin.mp;

import com.weasel.weixin.commons.message.CustomInitiativeMessageRequest;
import com.weasel.weixin.commons.message.CustomInitiativeMessageResponse;
import com.weasel.weixin.commons.message.bean.initiative.AbstractCustomInitiativeMessage;
import com.weasel.weixin.commons.message.builder.initiative.CustomInitiativeMessageBuilders;
import com.weasel.weixin.mp.builder.MpConfigBuilder;
import com.weasel.weixin.mp.config.MpConfig;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**主动向微信号发送消息测试
 * 运行main方法，通过注释和打开注释来测试各方法
 * Created by Dylan on 2015/10/16.
 */
public class CustomInitiativeMessageDemo {

    public static MpConfig config = null;
    public static CustomInitiativeMessageRequest request = null;
    static {

        try {
            config = MpConfigBuilder.fromXML("classpath:weixin-config.xml");
            request = new CustomInitiativeMessageRequest(config);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String [] args) throws IOException, ExecutionException {

        //sendTextMessage();
        //sendImageMessage();
        sendNewsMessage();

    }

    public static void sendTextMessage() throws IOException, ExecutionException {
        AbstractCustomInitiativeMessage message = CustomInitiativeMessageBuilders.TEXT()
                .toUser("oK8blwRGdeggPAKa-k3SoTym57Oc")
                .content("小明，明天早上来我办公室一下")
                .build();

        CustomInitiativeMessageResponse response = request.sendMessage(message);
        System.out.print(response);
    }

    public static void sendImageMessage() throws IOException, ExecutionException {

        AbstractCustomInitiativeMessage message = CustomInitiativeMessageBuilders.IMAGE()
                                                                                 .toUser("oK8blwRGdeggPAKa-k3SoTym57Oc")
                                                                                 .mediaId("2aLe038sgCjfr5NNeZF-fax0o18mJZupFdUsYTVVaW4")
                                                                                 .build();

        CustomInitiativeMessageResponse response = request.sendMessage(message);
        System.out.print(response);
    }

    public static void sendNewsMessage() throws IOException, ExecutionException {

        AbstractCustomInitiativeMessage message = CustomInitiativeMessageBuilders.NEWS()
                                                                                 .toUser("oK8blwRGdeggPAKa-k3SoTym57Oc")
                                                                                 .addArticle().title("茂名化州:两个14岁少女殒命于水塘")
                                                                                              .description("茂名化州:两个14岁少女殒命于水塘...")
                                                                                              .picUrl("http://g2.ykimg.com/0130391F4553572BD14930154C2C30FD9526B1-F29B-E881-0D89-1A826B7F9660")
                                                                                              .url("http://v.youku.com/v_show/id_XNzE4ODgyNjEy.html?from=y1.7-1.1")
                                                                                              .end()
                                                                                 .addArticle().title("马薇薇：“奇葩女王”诠释辩论人生")
                                                                                              .description("马薇薇：“奇葩女王”诠释辩论人生...")
                                                                                              .url("http://v.youku.com/v_show/id_XOTA4OTA2NTc2.html?from=y1.7-1.2")
                .end()
                                                                                 .build();
        CustomInitiativeMessageResponse response = request.sendMessage(message);
        System.out.print(response);
    }

}
